﻿// -----------------------------------------------------------------------
// <copyright file="Secure.cs" company="FCIS">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Security_Package.Management
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using CeaserChiper;
    using Data_Structure;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Secure : ISecure
    {
        /// <summary>
        /// object static from this class to use without make object of class
        /// </summary>
        private static Secure instance = new Secure();

        /// <summary>
        /// Gets or sets the instance.
        /// </summary>
        /// <value>
        /// The instance.
        /// </value>
        public static Secure Instance
        {
            get { return Secure.instance; }
            set { Secure.instance = value; }
        }

        /// <summary>
        /// Scures the input string by change it.
        /// </summary>
        /// <param name="input">The input string.</param>
        /// <param name="typeOfOperation">The type of operation encrypt or decrypt.</param>
        /// <param name="algo">The algo use.</param>
        /// <param name="keyOrKeyword">The key or keyword.</param>
        /// <param name="keytyp">The key type case vignere another case be null.</param>
        /// <returns>
        /// result string
        /// </returns>
        public string ScureInput(string input, TypeNeed typeOfOperation, AlgorithmUse algo, string keyOrKeyword, Vignere.KeyType keytyp)
        {
            try
            {
                switch (algo)
                {
                    case AlgorithmUse.CC:
                        {
                            CeaserChiper alg = new CeaserChiper();
                            switch (typeOfOperation)
                            {
                                case TypeNeed.Encrypt:
                                    {
                                        return alg.Encrypt(input, keyOrKeyword);
                                    }

                                case TypeNeed.Decrypt:
                                    {
                                        return alg.Decrypt(input, keyOrKeyword);
                                    }
                            }
                        }
                        
                        break;
                    case AlgorithmUse.PFC:
                        {
                            PlayFairAlgor.PlayFair alg = new PlayFairAlgor.PlayFair();
                            switch (typeOfOperation)
                            {
                                case TypeNeed.Encrypt:
                                    {
                                        return alg.Encrypt(input, keyOrKeyword);
                                    }

                                case TypeNeed.Decrypt:
                                    {
                                        return alg.Decrypt(input, keyOrKeyword);
                                    }
                            }
                        }

                        break;
                    case AlgorithmUse.Mono:
                        {
                            Monoalphabetic_Cipher.MonoalphabeticCipher alg = new Monoalphabetic_Cipher.MonoalphabeticCipher();
                            switch (typeOfOperation)
                            {
                                case TypeNeed.Encrypt:
                                    {
                                        return alg.Encrypt(input, keyOrKeyword);
                                    }

                                case TypeNeed.Decrypt:
                                    {
                                        return alg.Decrypt(input, keyOrKeyword);
                                    }
                            }
                        }

                        break;
                    case AlgorithmUse.columnar:
                        {
                            Columnar.Columnar alg = new Columnar.Columnar();
                            
                            switch (typeOfOperation)
                            {
                                case TypeNeed.Encrypt:
                                    {
                                        return alg.Encrypt(input, keyOrKeyword);
                                    }

                                case TypeNeed.Decrypt:
                                    {
                                        return alg.Decrypt(input, keyOrKeyword);
                                    }
                            }
                        }

                        break;
                    case AlgorithmUse.Vignere:
                        {
                            Vignere.Vignere alg = new Vignere.Vignere();
                            switch (typeOfOperation)
                            {
                                case TypeNeed.Encrypt:
                                    {
                                        return alg.Encrypt(input, keyOrKeyword, keytyp);
                                    }

                                case TypeNeed.Decrypt:
                                    {
                                        return alg.Decrypt(input, keyOrKeyword, keytyp);
                                    }
                            }
                        }

                        break;
                }

                return null;
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                throw;
            }
        }
    }
}
